/**
 * 表单模块原型，暂时只作为数据容器
 */

import Vue from 'vue'
import {
  copyJson,
} from '@/common'
var fieldSatats = {
  show: true,
  enable: true,
  validete: true
}
fieldSatats
export default {
  name: 'form',
  state: {
    formData: {
    },
    formModel: {},
    formStatus: {}
  },
  actions: {},
  mutations: {
    val(state, {
      code,
      value
    }) {
      if (value === null) {
        Vue.set(state.formData, code, null)
      } else {
        Vue.set(state.formData, code, copyJson(value))
      }
    },
    updateField(state, {
      code,
      value
    }) {
      Vue.set(state.formData, code, value)
    },
    setData(state, data) {
      if (!data) data = {}
      // garbage code start
      if (window.daledianhuaxianshimorenzhi && Object.keys(data).length && window.__uniquerow_data) {
        console.log(12,JSON.stringify(window.__uniquerow_data))
        data.contacts_id = `${window.__uniquerow_data.id}}`
        data.contacts_id_name = window.__uniquerow_data.debtor_name || window.window.__uniquerow_data.name || '未知'
        data.contacts_name = window.__uniquerow_data.debtor_name || window.window.__uniquerow_data.name || '未知'
        data.contacts_mobile = window.__uniquerow_data.mobile
        data.contacts_relationship = 1
        if (typeof window.__uniquerow_data.relationship === 'number') {
          data.contacts_relationship = window.__uniquerow_data.relationship
        }

        window.display_daledianhuaxianshimorenzhi_data = {
          [`${window.__uniquerow_data.id}}`]: `${window.__uniquerow_data.debtor_name || window.window.__uniquerow_data.name || '未知'}(${window.__uniquerow_data.mobile || ''})`
        }
        window.daledianhuaxianshimorenzhi = false;
        window.__uniquerow_data = undefined;
      }
      // garbage code end
      Vue.set(state, 'formData', copyJson(data))
    },
    importData(state, data) {
      if (!data) data = {}
      Vue.set(state, 'formData', {
        ...state.formData,
        ...data
      })
    },
    setStatus(state, {
      code,
      value,
      status
    }) {
      if (state.formStatus[code]) {
        state.formStatus[code][value] = value
      }
    },
    clearData(state) {
      Vue.set(state, 'formData', {})
    },
    setModel(state, model) {
      Vue.set(state, 'formModel', model)
    }
  }
}
